﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;
using Newtonsoft.Json;
using SzCourt.Logic.NBL.DBEntities;

namespace SzCourt.WebSite.manager
{
    public partial class AutoReplay : System.Web.UI.Page
    {
        public string _FirstList = string.Empty;
        public string _SecondList = string.Empty;
        public string _ThirdList = string.Empty;
        public string _FourthList = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            GetCauseOfActionList();
        }

        //获取案由类别
        private void GetCauseOfActionList()
        {
            PreCase bll = new PreCase();
            CauseOfActionList result = (CauseOfActionList)bll.GetCauseOfActionList();

            if (result != null)
            {
                this.sltFirstList.DataSource = result.FirstList;
                this.sltFirstList.DataTextField = "CauseOfAction";
                this.sltFirstList.DataValueField = "CauseOfActionID";
                this.sltFirstList.DataBind();

                _FirstList = JavaScriptConvert.SerializeObject(result.FirstList);
                _SecondList = JavaScriptConvert.SerializeObject(result.SecondList);
                _ThirdList = JavaScriptConvert.SerializeObject(result.ThirdList);
                _FourthList = JavaScriptConvert.SerializeObject(result.FourthList);
            }

            PreCase bllpc = new PreCase();
            List<pPreCaseAutoReply> listAutoReply = (List<pPreCaseAutoReply>)bllpc.GetCaseAutoReplyList();

            if (listAutoReply != null && listAutoReply.Count>0)
            {
                this.sltCaseAutoReply.DataSource = listAutoReply;
                this.sltCaseAutoReply.DataTextField = "AutoReplyTitle";
                this.sltCaseAutoReply.DataValueField = "CaseAutoReplyID";
                this.sltCaseAutoReply.DataBind();

                this.hdnID.Value = listAutoReply[0].CaseAutoReplyID.ToString();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            pPreAutoReplyMapping param = new pPreAutoReplyMapping();
            param.CaseAutoReplyID = int.Parse(this.hdnID.Value);
            param.CaseBriefID = int.Parse(this.sltCaseAutoReply.Value);
            
            PreCase bll = new PreCase();
            bool result = (bool)bll.MappingAutoReply(param);

            if (result)
            {
                this.divMessage.InnerHtml = "匹配成功!";
            }
            else
            {
                this.divMessage.InnerHtml = "匹配失败!";
            }
        }

    }
}